﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace System.Windows.Data
{

    /// <summary>
    /// Represents a single item within a data-bound control.
    /// </summary>
    public abstract class DataItemContentControl : ContentControl, ICommandContainer
    {

        /// <summary>
        /// Gets a command by name.
        /// </summary>
        /// <param name="commandName">The name of the command to lookup.</param>
        /// <returns>The command if its supported; null otherwise.</returns>
        protected virtual ICommand GetCommand(string commandName)
        {
            object dataItem = DataContext;
            if (dataItem == null)
            {
                return null;
            }

            return DataCommand.GetDataItemCommand(dataItem, commandName);
        }

        #region ICommandHandler Members
        ICommand ICommandContainer.GetCommand(string commandName)
        {
            return GetCommand(commandName);
        }
        #endregion
    }
}
